package com.mkx.rest.platform;

import com.mkx.application.dto.UserDTO;
import com.mkx.application.dto.request.CreateUserRequest;
import com.mkx.application.service.UserApplicationService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台端用户REST API控制器
 */
@RestController
@RequestMapping("/platform/users")
@Validated
public class PlatformUserController {
    
    @Resource
    private UserApplicationService userApplicationService;
    
    /**
     * 创建用户（平台端）
     * 平台管理员可以创建所有用户
     */
    @PostMapping
    public ResponseEntity<UserDTO> createUser(@Valid @RequestBody CreateUserRequest request) {
        // 平台端创建用户的业务逻辑
        UserDTO userDTO = userApplicationService.createUser(request);
        return new ResponseEntity<>(userDTO, HttpStatus.CREATED);
    }
    
    /**
     * 查询用户列表（平台端）
     * 平台管理员可以查看所有用户
     */
    @GetMapping
    public ResponseEntity<List<UserDTO>> findUsers(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        // 平台端查询所有用户的业务逻辑
        List<UserDTO> users = userApplicationService.findUsers(page, size);
        return ResponseEntity.ok(users);
    }
}